package com.ym.medical.service;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.ym.core.redis.RedisKeyEnum;
import com.ym.core.utils.tkmybatis.IBaseSV;
import com.ym.medical.domain.entity.CounsellingRoomEntity;
import com.ym.medical.domain.entity.DoctorStudioEntity;
import com.ym.medical.domain.entity.InquiryOrderEntity;
import com.ym.medical.domain.entity.UserEntity;
import com.ym.medical.domain.param.CancelOrderParam;
import com.ym.medical.domain.param.ConsultingOrderParam;
import com.ym.medical.domain.param.InquiryOrderParam;
import com.ym.medical.domain.param.OrderAndFileParam;
import com.ym.medical.domain.param.TdRecordExampleParam;
import com.ym.medical.domain.vo.*;
import com.ym.medical.enums.CounsellingRoomCourTypeEnum;
import com.ym.medical.enums.InquiryOrderIoTypeEnum;
import com.ym.medical.enums.InquiryOrderStateEnum;
import com.ym.medical.enums.OrderFlowRecordSatusEnum;

import java.util.Date;
import java.util.List;

/**
 * 问诊订单Service接口
 *
 * @author ym
 * @date 2020-08-24
 */
public interface IInquiryOrderSV extends IBaseSV<InquiryOrderEntity> {

	/**
	 * 根据ID查找
	 *
	 * @param id
	 * @return
	 */
	InquiryOrderEntity findById(long id);

	/**
	 * 根据model查找
	 *
	 * @param inquiryOrderModel
	 * @return
	 */
	InquiryOrderEntity findByModel(InquiryOrderParam inquiryOrderModel);

	/**
	 * 根据model列表查找
	 *
	 * @param inquiryOrderModel
	 * @return
	 */
	List<InquiryOrderEntity> list(InquiryOrderParam inquiryOrderModel);


	/**
	 * 抢单，下拉刷单方法
	 *
	 * @param generalDoctorPool
	 * @param currentUser
	 * @return
	 */
	public List<OrdersVo> getOrders(RedisKeyEnum generalDoctorPool, UserEntity currentUser);


	/**
	 * 抢单实现
	 *
	 * @param orderId     订单ID
	 * @param poolType    抢单池
	 * @param currentUser 当前用户
	 */
	void grabOrder(String orderId, RedisKeyEnum poolType, UserEntity currentUser);


	/**
	 * 接单后点击答复按钮
	 *
	 * @param orderId
	 * @param doctorId
	 * @param doctorType
	 * @return 聊天室ID
	 */
	Long answerOrder(Long orderId, Long doctorId, CounsellingRoomCourTypeEnum doctorType);


	/**
	 * 抢单后未回复,释放订单逻辑
	 *
	 * @param poolType 抢单池类型
	 * @param orderId  订单ID
	 * @param userId   用户ID
	 * @param extra    额外key
	 */
	void releasePoolOrder(RedisKeyEnum poolType, String orderId, Long userId, String... extra);

	/**
	 * 系统初始化,获取专科医生抢单池订单
	 *
	 * @return
	 */
	List<JSONObject> initSpecialistPool();

	/**
	 * 系统初始化,获取全科医生抢单池订单
	 *
	 * @return
	 */
	List<JSONObject> initGeneralPool();

	/**
	 * 系统初始化,获取全科医生已经抢到且未回复的订单
	 */
	List<JSONObject> getGeneralGrabUnReplay();

	/**
	 * 系统初始化,获取专科医生已经抢到且未回复的订单
	 */
	List<JSONObject> getSpecialistGrabUnReplay();

	/**
	 * 抢单后,到期自动完成订单
	 *
	 * @param orderId
	 * @param roomId
	 */
	void autoCompleteOrder(Long orderId, Long roomId);

	/**
	 * 更新咨询室状态
	 *
	 * @param counsellingRoom
	 * @return
	 */
	boolean updateStatus(CounsellingRoomEntity counsellingRoom);

	/**
	 * 订单-更新信息
	 *
	 * @param inquiryOrder
	 * @return
	 */
	boolean updateInquiryOrder(OrderAndFileParam inquiryOrder);

	/**
	 * 新增全科訂單
	 *
	 * @param inquiryOrder
	 * @return
	 */
	void saveOrder(InquiryOrderParam inquiryOrder);

	/**
	 * 获取医生电话问诊订单
	 * @param currId
	 * @param userType
	 * @param ioId
	 * @return
	 */
	List<OrderAndFileVO> selectOrderEcho(Long currId,String userType,Long ioId);

	/**
	 * 取消订单
	 *
	 * @param cancelOrderParam
	 * @return
	 */
	int cancelOrder(CancelOrderParam cancelOrderParam);

	/**
	 * 抢单后丢弃订单
	 *
	 * @param orderId     订单ID
	 * @param poolType    订单池类型
	 * @param currentUser 当前登录人
	 */
	void fallOrder(String orderId, RedisKeyEnum poolType, UserEntity currentUser);

	/**
	 * 退诊订单
	 *
	 * @param orderId 订单ID
	 */
	void withdrawalOrder(Long orderId);

	/**
	 * 根据订单ID，获取同类型的专科医生推荐
	 *
	 * @param orderId
	 * @return
	 */
	List<ResultDoctor> recommendOtherDoctors(Long orderId);

	/**
	 * 抢单并答复
	 *
	 * @param orderId
	 * @param poolType
	 * @param currentUser
	 */
	GrabAndAnswerVo grabOrderAnswer(String orderId, RedisKeyEnum poolType, UserEntity currentUser);

	/**
	 * 查询患者的未支付订单个数
	 *
	 * @param id
	 * @return
	 */
	Integer unPayNum(Long id);

	/**
	 * 患者端我的订单列表查询
	 *
	 * @param status
	 * @return
	 */
	List<MyOrderListVo> listMyOrdersPatient(Long userId, Long status);

	/**
	 * 患者端，我的订单详情
	 *
	 * @param orderId
	 * @return
	 */
	MyOrderInfoVo infoMyOrdersPatient(Long orderId);

	/**
	 * 根据订单id查询订单详情
	 *
	 * @param orderId
	 * @return
	 */
	public CounsellingRoomRecordVO selectOrderDesc(Long orderId);

	/**
	 * 医患账户更改
	 *
	 * @param orderId
	 */
	void updateDocDivide(Long orderId);

	/**
	 * 医生打电话前5分钟发送消息  注意接听电话通知
	 *
	 * @return
	 */
	List<InquiryOrderVo> beforeFiveMinutesOrder();

	/**
	 * 医生端-订单统计
	 *
	 * @param orderDate
	 * @param orderType
	 * @param doctorId
	 * @return
	 */
	List<OrdersVo> orderReport(String orderDate, String doctorType, String orderType, Long doctorId);

	/**
	 * 医生端，订单统计，详情
	 *
	 * @param orderId
	 * @param dsId
	 * @return
	 */
	MyOrderInfoVo orderReportInfo(Long orderId, DoctorStudioEntity dsId);

	/**
	 * 订单总金额统计
	 *
	 * @param orderDate
	 * @param orderType
	 * @param doctorId
	 * @return
	 */
	Double orderReportCountAmount(String orderDate, String doctorType, String orderType, Long doctorId);

	/**
	 * 未支付订单取消
	 *
	 * @param orderId
	 * @param orderFlowRecordSatusEnum 订单流转记录状态
	 * @param orderStateEnum 订单状态
	 */
	void unPayCancelOrder(Long orderId, OrderFlowRecordSatusEnum orderFlowRecordSatusEnum, InquiryOrderStateEnum orderStateEnum);

	/**
	 * 修改订单重新提交
	 *
	 * @param orderId
	 * @param attach
	 * @param content
	 */
	void orderRevision(Long orderId, String attach, String content);

	/**
	 * 根据订单号查询订单
	 *
	 * @param ioNum
	 * @return
	 */
	InquiryOrderEntity selectByIoNum(String ioNum);

	/**
	 * 电话问诊当天总量
	 *
	 * @param patientId
	 * @param time
	 * @return
	 */
	int selectCountPh(Long patientId, Date time);

	/**
	 * 根据预约规则ID，预约时间，订单类型，获取已预约的分钟数量
	 *
	 * @param appointTimeRule
	 * @param appointTime
	 * @param videoConsultation
	 * @return
	 */
	long getMinutesReserved(Long appointTimeRule, Date appointTime, InquiryOrderIoTypeEnum videoConsultation);

	/**
	 * 患者下单限制
	 * (相同医生同一患者不可重复下单)
	 *
	 * @param patientId
	 * @param doctId
	 * @return
	 */
	OrderVo samePatientLimit(long patientId, long doctId);

	/**
	 * 存在的订单
	 * @param dsId
	 * @return
	 */
	List<OrderVo> selectRepeatOrder(Long dsId, Long doctId, Long userId, Long patientId);

	/**
	 * 获取患者问诊医生的订单数量
	 * @return
	 */
	long getPatientAskNum(Long doctId,Long patientId);

	/**
	 * 查询患者义诊医生 (最多三次)
	 * @param userId 用户id
	 * @return
	 */
	List<Long> queryClinicTime(Long userId);

	/**
	 * 咨询订单列表查询
	 *
	 * @param query
	 * @return
	 */
	List<ConsultingOrderVO> consultingOrderList(ConsultingOrderParam query);

	/**
	 * 咨询订单详情
	 *
	 * @param orderId
	 * @return
	 */
	ConsultingOrderInfoVO consultingOrderInfo(Long orderId);

	/**
	 * PC端-账务系统 问诊交易记录
	 * @param  搜索条件构造
	 * @param pageNo
	 * @param limit
	 * @return
	 */
	PageInfo<InquiryTdRecordVO> listInquiryOrderRecord(TdRecordExampleParam tdRecordExampleVO, int pageNo, int limit);
}
